package com.platform.modules.wallet.take;

import cn.hutool.core.date.DateUtil;
import com.platform.common.config.PlatformConfig;
import com.platform.common.enums.YesOrNoEnum;
import com.platform.modules.chat.domain.ChatGroup;
import com.platform.modules.chat.service.ChatGroupMonitorService;
import com.platform.modules.chat.service.ChatGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class GruopMonitorTask {

    @Resource
    private ChatGroupService groupService;
    @Resource
    private ChatGroupMonitorService groupMonitorService;

    @Scheduled(cron = "10 * * * * ?")//"0 5/10 9-23 * * ?"
    public void runUpdateTotal() {
        if (PlatformConfig.MASTER.equals(YesOrNoEnum.NO)) return;
        List<ChatGroup> chatGroups = groupService.queryList(new ChatGroup().setTotal(YesOrNoEnum.YES));
        for (ChatGroup chatGroup : chatGroups) {
            groupMonitorService.updateTotal(chatGroup.getId());
        }

        System.out.println("这是每分钟统计" + DateUtil.date());
    }
}
